package com.epalmpay.service.member.impl;

import com.epalmpay.dto.xyMemberGrade.XyMemberGradeInDTO;
import com.epalmpay.dto.xyMemberGrade.XyMemberGradeListOutDTO;
import com.epalmpay.dto.xyMemberGrade.XyMemberGradeOutDTO;
import com.epalmpay.entity.Page;
import com.epalmpay.entity.XyMemberGrade;
import com.epalmpay.mapper.XyMemberGradeMapper;
import com.epalmpay.service.member.IXyMemberGradeService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/12/25.
 */
@Service("xyMemberGradeService")
public class XyMemberGradeServiceImpl implements IXyMemberGradeService{

    @Resource
    private XyMemberGradeMapper xyMemberGradeMapper;

    @Override
    public XyMemberGradeListOutDTO queryXyMemberGradeList(XyMemberGradeInDTO xyMemberGradeInDTO, Page page) throws Exception {

        XyMemberGradeListOutDTO xyMemberGradeListOutDTO = new XyMemberGradeListOutDTO();

        Map<String, Object> param = new HashMap<String, Object>();
        param.put("groupId", xyMemberGradeInDTO.getGroupId());
        param.put("gradename", xyMemberGradeInDTO.getGradename());
        param.put("joinStart", xyMemberGradeInDTO.getJoinStart());
        param.put("joinEnd", xyMemberGradeInDTO.getJoinEnd());

        int count = xyMemberGradeMapper.queryXyMemberGradeCount(param);
        page.setTotalResult(count);
        if(count<=0){
            return xyMemberGradeListOutDTO;
        }
        param.put("limit", page.getShowCount());
        param.put("start", page.getShowCount() * (page.getCurrentPage() - 1));

        List<XyMemberGradeOutDTO> xyMemberGradeOutDTOList = xyMemberGradeMapper.queryXyMemberGradeList(param);
        xyMemberGradeListOutDTO.setXyMemberGradeOutDTOList(xyMemberGradeOutDTOList);

        return xyMemberGradeListOutDTO;
    }

    @Override
    public XyMemberGradeOutDTO queryXyMemberGradeDetail(XyMemberGrade xyMemberGrade) {

        return xyMemberGradeMapper.queryXyMemberGradeDetail(xyMemberGrade);
    }
}
